home *** CD-ROM | disk | FTP | other *** search
/ Super Shareware Collection / Super Shareware Collection.iso / os_2 / ls351o.zip / LSORTOS2.DOC < prev    next >
Text File  |  1994-02-05  |  18KB  |  479 lines

  1. LSORTOS2 3.51 (C) Copyright London Computing, 1983-1993.
  2. All rights reserved.
  3.  
  4. LSORTOS2 is a general purpose sort/merge utility written in IBM CSet 2
  5. for IBM OS2 2.0 and above.  It runs on IBM PCs and compatibles with
  6. at least 8MB of RAM and a fixed disk.
  7.  
  8. LSORTOS2 is User Supported Software,  if this program proves useful, please
  9. make a contribution ($35 suggested) to:
  10.  
  11. London Computing, P.O. Box 696  Cherry Hill, NJ 08003
  12.  
  13. Anyone sending a contribution will receive a disk containing the source
  14. code to LSORTOS2 as well as a copy of the LSRTOS2 sort filter.  LSRTOS2 is
  15. similar to the SORT filter but works much faster and will sort on
  16. multiple fields.
  17.  
  18. You may make copies of this software and distribute to other users as long as
  19. there is no charge or other consideration and this notice is not removed or
  20. bypassed.
  21.  
  22. LSORTOS2 will sort MSDOS, OS2 files and dBase II and dBase III
  23. databases.  (dBase III memo files and FOXPRO memo files are not sorted
  24. but .DBF files will be sorted.) Each file may be sorted using 1 to 32
  25. sort fields.  The file to be sorted may contain either fixed length
  26. records, variable length records or comma delimited records.  Variable
  27. length records are records ending with cr/lf.  Comma delimited records
  28. are variable length records where the fields are also variable length
  29. and separated by a comma.  Character fields may be enclosed in either
  30. single or double quotes.  It will merge up to 5 files using 1 to 32
  31. sort fields.  dBase databases may not be merged.  Any field may be
  32. sorted in either ascending or descending sequence.  LSORTOS2 allows for
  33. three user defined field types to be used: X,Y and Z.  You must write
  34. your own comparison subroutine to compare user defined fields.
  35.  
  36. The sort knows about:                       field type
  37.  
  38. binary fields (to 127 bytes)                      B
  39.    A binary field is compared left to right
  40.    based on value of the code in each field
  41.    (0-255).  It is useful for comparing strings
  42.    where binary zeros are embedded and for
  43.    comparing IBM Mainframe stype binary numbers
  44. packed decimal fields (1-8 bytes) Stored as on    P
  45.    IBM Mainframe computers.  Each digit position
  46.    is stored in 4 bits as a binary value between
  47.    0 and 10.  The digits are stored left to
  48.    right with the rightmost position containing
  49.    a sign, 0x0D for negative, 0x0C or 0x0F for
  50.    positive.  A packed decimal field can store
  51.    between 1 and 15 digits depending on the
  52.    length of the field.  If an invalid sign
  53.    field is specified, the sort won't produce
  54.    what you would expect.  Packed decimal values
  55.    are only meaningful in fixed length record.   
  56. character fields (to 127 bytes)                   C
  57.    character fields compare up to the first
  58.    binary zero in the field following C
  59.    language conventions.
  60. upper case character fields (sort fields are      U
  61.    translated to upper case before compare)
  62. 2 byte integers in internal  format               I
  63. 4 byte integers in internal format                L
  64. floating point numbers (ieee)                     F
  65. double precision floating point (ieee)            D
  66. zoned decimal  numbers                            N
  67.    (Text format numbers,  Decimals are allowed)
  68.    (LSORTOS2 now supports scientific notation as)
  69.    (well, using E notation, eg. .98 == 9.8E-1)
  70.    (xBase N and F fields are sorted as type N)
  71. 1 byte logical fields (dBase II or III)           T
  72. User defined field type X                         X
  73. User defined field type Y                         Y
  74. User defined field type Z                         Z
  75.  
  76. A zoned decimal number is stored as a character string and may contain
  77. leading and trailing spaces, minus sign, decimal point and digits.
  78.  
  79. NOTE: zoned decimal numbers and comma delimitted files sort very slowly!
  80. The only reasonable field types for comma delimited files are C or N. LSORTOS2
  81. will accept other field types, but the results are undefined.
  82.  
  83.  
  84. LSORTOS2 will prompt you for all parameters and file names or you may specify
  85. some or all of the parameters on the command line when you invoke the sort.
  86.  
  87. The maximum record length is 4096 bytes.  Files will be sorted in memory if
  88. possible.
  89.  
  90. Files larger than available memory are sorted in pieces and then merged
  91. together.  If you have a floppy only system, you should have LSORTOS2 on the A
  92. drive and the file to be sorted on the B drive.  Place a copy of LSORTOS2 on an
  93. otherwise empty disk and use as your A drive.  You may need a formatted empty
  94. disk for work files on the B drive.
  95.  
  96.  
  97. SYNTAX:
  98.  
  99.  
  100. LSORTOS2 [-h | -m] -- will prompt you for all necessary information.
  101.  or
  102. LSORTOS2 [-h | -m] sort specifications--will take the specification specified and
  103.                   prompt you for any others.
  104.  
  105. Specify -h if you are using a fixed (hard disk) for your output and
  106. merge files.  This will eliminate mount messages.  This is the default
  107. for LSORTOS2 3.01 and above.  Specify -m if you are using mountable disks
  108. (floppy, Bournouli, etc.).  This allows you to mount disks to contain
  109. work files and output files.
  110.  
  111.  or
  112.  
  113. LSORTOS2 -R  -- will restart a sort.
  114.  
  115.  
  116. Sort Specifications:
  117.  
  118. You will be asked to specify either a SORT or MERGE operation.
  119.  
  120. If you ask for a SORT, you may tell LSORTOS2 to use either a QUICKSORT or
  121. HEAPSORT for internal sorting.  You will also be asked to specify two
  122. devices to hold merge files if any are needed.  Merge files may be placed on
  123. floppy disk, hard disk or RAM disk.  The specified drive must be large
  124. enough to hold the entire input file.  You will be given the opportunity to
  125. change floppy disks if desired before each merge drive is used and before
  126. the output file is written.  The program will wait for you to press 'Y'
  127. before proceeding.  This is not really a problem for unattended sorting
  128. if you use redirected input or specify all prompts on the command line.
  129.  
  130. If you specify SORT or MERGE you will be prompted for your input file(s) and
  131. output file as well as the definition of the key fields to be used in the
  132. comparisons.  Fields are specified by their starting position and length.
  133. The types of fields have been listed above.
  134.  
  135. The sort specifications may be entered on the command line in the order
  136. requested by LSORTOS2. Each parameter should be separated from the others with
  137. one or more spaces.  You will not be prompted for any specification on the
  138. command line (including requests to change disks).
  139.  
  140. The sort will ask for the following information in the order shown:
  141.  
  142. Type of Sort:  You may reply:
  143. S -- for QUICKSORT
  144. H -- for HEAPSORT
  145.  
  146. Merge Drive 1:  You may reply with any drive letter, although it is best to
  147. specify a fixed disk (if any).
  148.  
  149.  
  150. Merge Drive 2:  This should be different from drive 1 if you are using
  151. floppy disks, but should be a fixed disk if you have one.
  152.  
  153. Name of input file: You may specify any name including drive letter and
  154. path.  Specify :X to use a user specified input routine.
  155.  
  156. Name of output file:  See above.  Specify :X to use a user specified output
  157. routine.
  158.  
  159. File Type (Unless you are sorting a dBase file):  You may reply F for a
  160. fixed length file (all records are the same length), V for a varying
  161. length file (records must end with CR LF.) or D for comma delimited files.
  162.  
  163.  
  164. If you entered 'F' for a fixed file, you will be prompted for the record
  165. length.
  166.  
  167. You will then be prompted for field definitions.  Each field definition has
  168. four parts:    starting position (from 1)  or  starting field (delimited files)
  169.                field length (in bytes)         (no prompt for delimited files)
  170.                field type (See above list of valid types)
  171.                sort order (A--Ascending, D--Descending)
  172.  
  173. In order to work as efficiently as possible, LSORTOS2 does not check the
  174. starting position of a field against the actual length of a record.  If some
  175. field starts past the end of a record (e.g. sort field 1 starts in column 10
  176. but the record is only 8 bytes long), the results will be undefined and most
  177. certainly not what you want.  Please be careful.
  178.  
  179. Enter a '0' for the starting position to end the prompt for field
  180. definitions.
  181.  
  182. If you are sorting a dBase file, you will see a list of fields.  You may
  183. specify a field by name, in which case you will only be prompted for the
  184. sort order or you may enter starting position, length, type and order as
  185. above.
  186.  
  187. Following the '0' that ends field definitions, you may specify a series of
  188. 'Y's if you know that the disks currently mounted will hold merge work files
  189. and the output file.  These may be omitted if you specified the -H flag.
  190.  
  191. example 1:
  192.  
  193. Sort file test.dat on positions 1-5,char,ascending and 6-7, binary integer,
  194. descending.  Use drive C for the work files and put the sorted file in
  195. test.srt.
  196.  
  197. Issue the following command:
  198.  
  199. LSORTOS2 S C C test.dat test.srt V 1 5 C A 6 2 H D 0 Y Y Y
  200.          | | | |        |        | |_____| |_____| | | | |
  201.          | | | input    output   F |       |       | | | response to mount
  202.          | | | file     file     i sort    sort    | | | output file message.
  203.          | | | name     name     l field 1 field 2 | | |
  204.          | | |                   e starts  starts  | | response to mount 2nd
  205.          | | merge drive 2         at byte at byte | | merge volume message.
  206.          | |                     T 1, is 5 6, is 2 | |
  207.          | merge drive 1         y byte    byte    | response to mount first
  208.          |                       p char-   long    | merge volume message.
  209.          sort using              e acter   integer |
  210.          quicksort                 string  sorted  ends list of sort fields.
  211.                                    ascend- descend-
  212.                                    ing     ing
  213.  
  214.  
  215.  
  216. Merge Specification:
  217.  
  218. Enter 'M' to indicate the merge operation.
  219.  
  220. You will be asked to enter the number of files to be merged followed by 1-5
  221. files to be merged. They are entered one at a time.
  222.  
  223. You will be asked to enter a file type, output file and a field list as
  224. above.
  225.  
  226. example:
  227.  
  228. Merge files t1.dat t2.dat and t3.dat on positions 4-7 defined as a character
  229. field, ascending.
  230.  
  231. LSORTOS2 M 3 t1.dat t2.dat t3.dat   test.mrg V 4 4 c a 0 y y
  232.          | | |      |      |        |        | |_____| | |_|
  233.          | | input  input  input    output   | |       | |
  234.          | | file 1 file 2 file 3   file     | merge   | response to mount
  235.          | |                                 | field   | messages
  236.          | merge 3 files                     | 1       |
  237.          |                                   |         end of list of merge
  238.          do a merge                          file      fields
  239.                                              type
  240. Restarting:
  241.  
  242. If a sort stops in the middle due to lack of space or is stopped by you by
  243. pressing ^BREAK, it may be restarted by issuing the LSORTOS2 -R command
  244. providing the dataset(s), SORTPARM.DAT and (DB3PARM.DAT for dBase III files
  245. only) are still available and further providing all files LSMERGE?.DAT are
  246. still available. The sort will be restarted at the beginning of the LSSORT
  247. phase (where the input file is read and sorted) or at the beginning of an
  248. LSMERGE pass, where several partially sorted files are combined.
  249.  
  250. User Exits:
  251.  
  252. You may define your own user exits to read and write data and you may define
  253. your own compare routines for the standard field types or for user defined
  254. field types.  These routines must be written in Microsoft C 6.0 or in
  255. any other language that can be linked to Microsoft C 6.0.
  256.  
  257. User input:  (Available for Sorting Only)
  258.  
  259. Specify :X as the name of the input file.  LSORTOS2 uses a routine named
  260. USERIP to read the records to be sorted.  You may write your own
  261. version of USERIP and link it with LSORTOS2 to create a custom version
  262. containing your own input routine.
  263.  
  264. USERIP is used as follows:
  265.  
  266. int l,userip();
  267. char buffer[...];
  268.  
  269. l = userip(buffer);
  270.  
  271. USERIP must return the length of the record read which must be <= 4096
  272. or -1 for end of file.  If you have specified V type files, USERIP must
  273. return a string ending with a '\0'.  The string length must include the
  274. trailing '\0'.
  275.  
  276. User Output:
  277.  
  278. Specify :X as the name of the output file.  LSORTOS2 uses a routine called
  279. USEROP to write to the :X file.  You may write your own user output
  280. routine to be used to write the final sorted or merged output by
  281. creating a custom version of USEROP and relinking LSORTOS2 to create a
  282. custom LSORTOS2.  USEROP works as follows:
  283.  
  284. int buflen;
  285. char buffer[...];
  286.  
  287. userop(buffer,buflen);     /* userop must write buflen bytes from buffer */
  288.                            /* buflen == 0 means that you want to write a
  289.                               0 terminated string */
  290. userop(NULL,-1);           /* userop must perform end of file processing */
  291.  
  292.  
  293. Sample versions of userip and userop appear below:
  294. /* Userip to return a varying length string */
  295. #define CPMEOF 26
  296. #include "stdio.h"
  297. userip(s)
  298. char *s;
  299. {
  300.  static char firsttime = 1;
  301.  static int inchan;
  302.  char *fgets();
  303.  int l;
  304.  /* input is string buffer, max length 4k, 4k always available      */
  305.  /* this routine must return length of string or EOF if end of file */
  306.  /* example follows: (Note length of string includes 0 byte at end  */
  307.       if (firsttime) {
  308.             firsttime=0;
  309.             inchan=fopen("usertest.dat","r");
  310.       }
  311.       if (fgets(s,4096,inchan))
  312.             return strlen(s)+1;
  313.       else
  314.             return EOF;
  315. }
  316.  
  317. /* Userip to return a fixed length string */
  318. #define CPMEOF 26
  319. #define STRLEN 128
  320. #include "stdio.h"
  321. userip(s)
  322. char *s;
  323. {
  324.  static char firsttime = 1;
  325.  static int inchan;
  326.  char *fgets();
  327.  int c,l;
  328.  /* input is string buffer, max length 4k, 4k always available      */
  329.  /* this routine must return length of string or EOF if end of file */
  330.  /* example follows: (Note length of string includes 0 byte at end  */
  331.       if (firsttime) {
  332.             firsttime=0;
  333.             inchan=fopen("usertest.dat","r");
  334.       }
  335.       if ((l=read(inchan,buffer,STRLEN)) == STRLEN)
  336.             return STRLEN;
  337.       else
  338.             return EOF;
  339. }
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349. userop(s,l)
  350. char *s;
  351. int l;
  352. {
  353. /* s is string to write, l is length or 0 if 0 terminated or -1 for close */
  354.       static char firsttime = 1;
  355.       static int otchan;
  356.       if (firsttime) {
  357.             firsttime = 0;
  358.             otchan = fopen("usertest.srt","w");
  359.       }
  360.       
  361.       if (l == -1 || s == NULL)
  362.             fclose(otchan);
  363.       else if (l) /* write an F type record */
  364.             while(l--) fputc(*s++,otchan);
  365.       else fputs(s,otchan); /* write a V type record */
  366. }
  367.             
  368.  
  369. User Compare Routines:
  370.  
  371. You may define up three user defined fields: X,Y,Z.  You must write a compare
  372. routine for each field type used.  The routine names are:
  373.  
  374.       sxcmp --  for field type X.
  375.       sycmp --  for field type Y.
  376.       szcmp --  for field type Z.
  377.  
  378. The compare routines are called with three arguments, the address of the
  379. first field, the address of the second field and the field length. The
  380. routine must return 1 if field 1 < field 2, 0 if field1 == field2 and -1 if
  381. field1 > field2.
  382.  
  383. Sample routines are shown below:
  384.  
  385. sxcmp(a,b,l)
  386. long int *a,*b;
  387. int l;
  388. { /* this routine compares two long integers */
  389. long int c;
  390. c = *a - *b;
  391. return c <0 ? -1 : c == 0 ? 0 : 1;
  392. }
  393.  
  394. sycmp(a,b,l)
  395. int *a,*b;
  396. int l;
  397. { /* this routine compares two integers (2 bytes) */
  398. int c;
  399. c = *a - *b;
  400. return c <0 ? -1 : c == 0 ? 0 : 1;
  401. }
  402.  
  403.  
  404. szcmp(a,b,l)
  405. float *a,*b;
  406. int l;
  407. { /* this routine compares two floating numbers */
  408. float c;
  409. c = *a - *b;
  410. return c<0 ? -1 : c == 0 ? 0 : 1;
  411. }
  412.  
  413.  
  414.  
  415. Linking user written routines:
  416.  
  417. Compile your user written routines using Visual C++ for NT.  
  418.  
  419. Create a program list containing the following lines
  420.  
  421. LSORTOS2.obj +
  422.                   <=== place your routines here       
  423. LSORTcmp.obj +
  424. LSORTdbf.obj +
  425. LSORTio.obj +
  426. LSORTprm.obj +
  427. LSORTqk.obj +
  428. LSORTsub.obj +
  429. lssort.obj +
  430. lsuser.obj +
  431. lsmerge.obj
  432.  
  433. and re-link LSORTOS2 with the following statement:
  434.  
  435.  
  436. LSOS2 is a Graphical Front End for LSORTOS2.  To run the front end,
  437. type LSOS2 from a command line or create an icon as shown below:
  438.  
  439. LSOS2 is a full function sort program with a Windows front end.
  440.  
  441. It consists of:
  442. LSOS2.CMD -- The command file that start LSOS2
  443. LSORTWN3.EXE  -- a Visual Basic front end to LSORT (DOS,OS/2 and NT) and
  444. DB3COPYW.EXE  -- a Windows Utility to display all or part of an xBase file.
  445. CMDIALOG.VBX
  446. STRTOHEX.DLL
  447.  
  448. VBRUN300.DLL is required to run Visual Basic executables.  It is not 
  449. included but is avaiable on Compuserv and other BBS's.
  450.  
  451. To install LSORTOS2 for Windows, copy the files LSORTWN3.EXE
  452. and DB3COPYW.exe to your WINDOWS directory.  If you do not own Visual
  453. Basic and have not previously downloaded a copy of VBRUN300.DLL, copy
  454. VBRUN300.DLL to your WINDOWS directory.  Copy CMDIALOG.VBX and
  455. STRTOHEX.DLL to your Windows directory.
  456.  
  457. After all the files have been copied, add the program to an existing
  458. group or create a new group for LSORTOS2.  To add LSORTOS2 for Windows to a
  459. group, open the group, then click on File then New.  A dialog box will
  460. be displayed asking if you wish to create a new Item or new Group. 
  461. Click on Program Item to add a new item to the existing group.  A
  462. dialog box will be displayed asking for the program description and
  463. command line.  Enter "LSORTOS2 for Windows" in the description field.
  464. Enter "LSOS2" in the command line field.  Click OK.  LSORTOS2 for
  465. Windows will now be available.
  466.  
  467. LSOS2 provides a menu driven front end for LSORTOS2.  It allows you to
  468. use familiar windows tools to select the input and output files and define
  469. the SORT fields.  The help function will tell you how to use it.
  470.  
  471. When using LSOS2, you must always define an input and output file
  472. and define your SORT fields.  You may optionally pick a sorting
  473. algorithm (Help Sort or Quick Sort), define the locations of Work
  474. Files, determine the file type (Text, Comma Delim, Fixed Record or
  475. xBase) and view the file prior to sorting.  When selecting the sort
  476. fields, LSOS2 will display the database structure in a Listbox.
  477.  
  478.  
  479.